package org.grow.mskeeper.config;

import org.grow.dto.AppNames;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: xwg
 * @CreateDate: 2022/6/1
 */

@Configuration
public class RouteConfig {

    public static final String loadBalancePrefix = "lb://";

    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("basic模块", r -> {
                    return r.path("/basic/**")
                            .uri(loadBalancePrefix + AppNames.basic);
                })
                .route("tool模块", r -> {
                    return r.path("/support/**")
                            .uri(loadBalancePrefix + AppNames.support_ms);
                })
                .route("basic_module", r -> {
                    return r.path("/swimming/**")
                            .uri(loadBalancePrefix + AppNames.basic);
                })
                .route("auth_module", r -> {
                    return r.path("/login","/logout")
                            .uri(loadBalancePrefix + AppNames.auth);
                })
                .build();
    }
}
